import InstallCommon
import os

def DisplayApache2ConfigurationInstructions():
    FileName = '/etc/apache2/sites-enabled/000-default.conf'
    print "Example:  Write the following to the file:  " + FileName
    print Apache2_sites_available_default
    
    print "\n\n******************************************************************************\n\n"
    print "Run:  " + "/usr/sbin/a2enmod alias"
    FileName = '/etc/apache2/mods-enabled/alias.conf'
    print "Example:  Write the following to the file:  " + FileName 
    print apache2_alias_conf    



    print "\n\n******************************************************************************\n\n"
    FileName = '/etc/apache2/apache2.conf'
    print "Example:  Write the following to the file:  " + FileName 
    print apache2_conf



    print "\n\n******************************************************************************\n\n"
    FileName = '/etc/apache2/mods-enabled/wsgi.load'
    print "Example:  Write the following to the file:  " + FileName 
    print apache2_wsgi_load  

    print "\n\n******************************************************************************\n\n"
    print "Then restart the apache server:"
    print "/etc/init.d/apache2 restart"

    print "\nIf you place Apache2 on an alternate port (such as for testing) make sure to add the port to the ports.conf file."
    Response = raw_input().lower()

COOPGISWSGIFile = InstallCommon.PythonPath + 'django.wsgi'
Apache2_sites_available_default="""<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    
    DocumentRoot /var/www/html/
    <Directory />
#    DirectoryIndex index.html
#        AuthType None
#        Options FollowSymLinks
#        AllowOverride None
#        Require all granted
    </Directory>
    <Directory /var/www/html/>
#        DirectoryIndex index.html
#
#	Options Indexes FollowSymLinks MultiViews
#	AllowOverride None
#        Require all granted
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    # Possible values: debug, info, notice, warn, error, crit, alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
   
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Require all denied
    #    Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

    Alias /style.css /var/www/style.css
    Alias /openlayers /var/www/openlayers/
    <Directory /var/www/openlayers/>
        Require all granted
    </Directory>

    Alias /images/ /var/www/images/
    <Directory /var/www/images>
        Require all granted
    </Directory>


</VirtualHost>

    WSGIScriptAlias /coopgis """ + COOPGISWSGIFile + """
    WSGIPythonPath """ + InstallCommon.PythonPath + """>
    <Directory """ + InstallCommon.PythonPath + """>
        <Files wsgi.py>
             Require all granted
        </Files>
    </Directory>"""








apache2_alias_conf="""<IfModule alias_module>
#
# Aliases: Add here as many aliases as you need (with no limit). The format is 
# Alias fakename realname
#
# Note that if you include a trailing / on fakename then the server will
# require it to be present in the URL.  So "/icons" isn't aliased in this
# example, only "/icons/".  If the fakename is slash-terminated, then the 
# realname must also be slash terminated, and if the fakename omits the 
# trailing slash, the realname must also omit it.
#
# We include the /icons/ alias for FancyIndexed directory listings.  If
# you do not use FancyIndexing, you may comment this out.
#
Alias /icons/ "/usr/share/apache2/icons/"

<Directory "/usr/share/apache2/icons">
    Options FollowSymlinks
    AllowOverride None
    Require all granted
</Directory>

</IfModule>"""

apache2_wsgi_load="""
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so"""

apache2_conf = """
LoadModule cgi_module /usr/lib/apache2/modules/mod_cgi.so
AddHandler cgi-script .cgi"""


